﻿/**
 * File:   gesture_lock.h
 * Author: AWTK Develop Team
 * Brief:  九宫格手势密码控件。
 *
 * Copyright (c) 2021 - 2021 Guangzhou ZHIYUAN Electronics Co.,Ltd.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * License file for more details.
 *
 */

/**
 * History:
 * ================================================================
 * 2021-02-20 Zhang Zhongji <zhangzhongji@zlg.cn> created
 *
 */


#ifndef TK_GESTURE_LOCK_H
#define TK_GESTURE_LOCK_H

#include "base/widget.h"

BEGIN_C_DECLS
typedef enum _gesture_lock_state_t {
  INIT,
  PRESSED,
  PASS,
  FAILED
} gesture_lock_state_t;

/**
 * @class gesture_lock_t
 * @parent widget_t
 * @annotation ["scriptable","design","widget"]
 * 九宫格手势密码控件。
 * 在xml中使用"gesture\_lock"标签创建控件。如：
 *
 * ```xml
 * <!-- ui -->
 * <gesture_lock x="c" y="50" w="100" h="100"/>
 * ```
 *
 * 可用通过style来设置控件的显示风格，如字体的大小和颜色等等。如：
 * 
 * ```xml
 * <!-- style -->
 * <gesture_lock>
 *   <style name="default" font_size="32">
 *     <normal text_color="black" />
 *   </style>
 * </gesture_lock>
 * ```
 */
typedef struct _gesture_lock_t {
  widget_t widget;


  /**
   * @property {int32_t} min_points
   * @annotation ["set_prop","get_prop","readable","persitent","design","scriptable"]
   * 最少选中的点的个数。。
   */
  int32_t min_points;

/* private */
  gesture_lock_state_t state;
  point_t base_points[9];
  darray_t *password;
  darray_t *input_password;
  point_t current_position;
  bool_t setting_password;
  float_t r;
} gesture_lock_t;

/**
 * @method gesture_lock_create
 * @annotation ["constructor", "scriptable"]
 * 创建gesture_lock对象
 * @param {widget_t*} parent 父控件
 * @param {xy_t} x x坐标
 * @param {xy_t} y y坐标
 * @param {wh_t} w 宽度
 * @param {wh_t} h 高度
 *
 * @return {widget_t*} gesture_lock对象。
 */
widget_t* gesture_lock_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h);

/**
 * @method gesture_lock_cast
 * 转换为gesture_lock对象(供脚本语言使用)。
 * @annotation ["cast", "scriptable"]
 * @param {widget_t*} widget gesture_lock对象。
 *
 * @return {widget_t*} gesture_lock对象。
 */
widget_t* gesture_lock_cast(widget_t* widget);


/**
 * @method gesture_lock_set_min_points
 * 设置 最少选中的点的个数。
 * @annotation ["scriptable"]
 * @param {widget_t*} widget widget对象。
 * @param {int32_t} min_points 最少选中的点的个数。。
 *
 * @return {ret_t} 返回RET_OK表示成功，否则表示失败。
 */
ret_t gesture_lock_set_min_points(widget_t* widget, int32_t min_points);

/**
 * @method gesture_lock_reset_password
 * 重置密码。
 * @annotation ["scriptable"]
 * @param {widget_t*} widget widget对象。
 *
 * @return {ret_t} 返回RET_OK表示成功，否则表示失败。
 */
ret_t gesture_lock_reset_password(widget_t* widget);

#define GESTURE_LOCK_PROP_MIN_POINTS "min_points"

#define WIDGET_TYPE_GESTURE_LOCK "gesture_lock"

#define GESTURE_LOCK(widget) ((gesture_lock_t*)(gesture_lock_cast(WIDGET(widget))))

/*public for subclass and runtime type check*/
TK_EXTERN_VTABLE(gesture_lock);

END_C_DECLS

#endif /*TK_GESTURE_LOCK_H*/
